package com.ibm.cps.servlet.starter;

import org.apache.log4j.Logger;

import com.ibm.util.exception.CPSException;

/**
 * Created by telekinesis on 6/23/15.
 */
public class CommandlineApp implements WorkerProcess {
	private static final Logger logger = Logger.getLogger(CommandlineApp.class);
    private final Process process;
    private final String name;

    public CommandlineApp(Process process, String name) {
        this.process = process;
        this.name = name;
    }

    @Override
    public void stop() throws CPSException{
        process.destroy();
    }

	@Override
	public boolean isAlive() {
		try{
			int retValue = process.exitValue();
			logger.info("User agent " + name + " terminated with exit value " + retValue);
			return false;
		}catch(IllegalThreadStateException stillRunning){
			return true;
		}
	}
    
    
}
